import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/Login.vue'
import Register from '../components/Register.vue'
import Recove from '../components/recove/Recove.vue'
import Home from '../components/home/Home.vue'
import Personal from '../components/personal/personalCenter.vue'
import Sevice from '../components/home/Sevice.vue'
import paymentRecords from '../components/personal/paymentRecords.vue'
import paymentDetails from '../components/personal/paymentDetails.vue'
import refundDetails from '../components/personal/refundDetails.vue'
import phonePage from '../components/recoverPsw/phonePage.vue'
import resetPsw from '../components/recoverPsw/resetPsw.vue'
import personPayment from '../components/personal/personPayment.vue'
import address from '../components/personal/address.vue'
import personalInvoice from '../components/personal/personalInvoice.vue'
import invoicePreview from '../components/personal/invoicePreview.vue'
import invoiceRecords from '../components/personal/invoiceRecords.vue'
import companyPayment from '../components/personal/companyPayment.vue'
import changePwd from '../components/personal/changePwd.vue'
import refundNotice from '../components/home/refundNotice.vue'

Vue.use(VueRouter)

const routes = [
  { path: '/', redirect: '/login' },
  { path: '/login', component: Login },
  { path: '/register', component: Register },
  { path: '/recove', component: Recove },
  { path: '/phonePage', component: phonePage },
  { path: '/resetPsw', component: resetPsw },
  { path: '/personPayment', component: personPayment },
  { path: '/address', component: address },
  { path: '/personalInvoice', component: personalInvoice },
  { path: '/invoicePreview', name: 'invoicePreview', component: invoicePreview },
  { path: '/invoiceRecords', component: invoiceRecords },
  { path: '/companyPayment', component: companyPayment },
  { path: '/changePwd', component: changePwd },
  { path: '/refundNotice', component: refundNotice },
  {
    path: '/home',
    component: Home,
    redirect: '/sevice',
    children: [
      { path: '/sevice', component: Sevice },
      { path: '/personal', component: Personal },
      { path: '/paymentRecords', component: paymentRecords }
    ]
  },
  { path: '/paymentDetails', component: paymentDetails },
  { path: '/refundDetails', component: refundDetails }
]

const router = new VueRouter({
  routes
})

// 挂载路由导航守卫
// router.beforeEach((to, from, next) => {
//   if (to.path === '/login' || to.path === '/register') return next()
//   // 获取token
//   const tokenStr = window.sessionStorage.getItem('token')
//   if (!tokenStr) return next('/login')
//   next()
// })

export default router
